package currency;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

class LockTest extends Accumulator {
    {
        mId = "Lock";
    }

    private Lock mLock = new ReentrantLock();

    @Override
    public void accumulate() {
        mLock.lock();
        try {
            mValue += sPreLoaded[mIndex++];
            if (mIndex >= SIZE) {
                mIndex = 0;
            }
        } finally {
            mLock.unlock();
        }
    }

    @Override
    public long read() {
        mLock.lock();
        try {
            return mValue;
        } finally {
            mLock.unlock();
        }
    }
}
